import service from "@/api/index.js";

const cartApi = {
//     添加购物车
    addInfo(goodsId){
        return service.post(`/cart/${goodsId}`)
    },
//     获得购物车中商品数量
    getCartNumber(goodsId) {
        return service.get(`/cart/number/${goodsId}`)
    },
//     删除
    delInfo(id) {
        return service.delete(`/cart/${id}`)
    },
//    修改
    updateInfo(cart) {
        return service.put('/cart',cart)
    },
//     查询
    getAll() {
        return service.get('/cart')
    },
    getByIdList(cartIdList) {
        let params = '?cartId='
        if (typeof cartIdList === "string") {
            params += cartIdList
        } else {
            for (let i = 0; i < cartIdList.length; i++) {
                params += cartIdList[i]
                if (i !== cartIdList.length - 1) {
                    params += '&cartId='
                }
            }
        }
        return service.get(`/cart/idList${params}`)
    }
}
export default cartApi